package com.browan.constellation.weibo;

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.signature.SignatureMethod;

public class TockenManager
{
	private String tocken;
	private String tocken_secret;
	private String auth_number;

	private TockenManager()
	{
	}

	public String initTocken() throws Exception
	{
		OAuthConsumer consumer = new DefaultOAuthConsumer(AppManager.APP_KEY, AppManager.APP_SECRET,
				SignatureMethod.HMAC_SHA1);
		OAuthProvider provider = new DefaultOAuthProvider(consumer, UriManager.REQUEST_TOKEN, UriManager.ACCESS_TOCKEN,
				UriManager.AUTHORIZE);
		String authUrl = provider.retrieveRequestToken(OAuth.OUT_OF_BAND);

		this.tocken = consumer.getToken();
		this.tocken_secret = consumer.getTokenSecret();
		return authUrl;
	}

	private static TockenManager manager;

	public static TockenManager getInstence()
	{

		if (null == manager)
		{
			manager = new TockenManager();

		}

		return manager;
	}

	public String getTocken()
	{
		return tocken;
	}

	public void setTocken(String tocken)
	{
		this.tocken = tocken;
	}

	public String getTocken_secret()
	{
		return tocken_secret;
	}

	public void setTocken_secret(String tockenSecret)
	{
		tocken_secret = tockenSecret;
	}

	public String getAuth_number()
	{
		return auth_number;
	}

	public void setAuth_number(String authNumber)
	{
		auth_number = authNumber;
	}

	@Override
	public String toString()
	{
		return "tocken:" + this.tocken + "-secret:" + this.tocken_secret + "-authNumber:" + auth_number;
	}
}